home *** CD-ROM | disk | FTP | other *** search
- #include "main.h"
- #include "menus.h"
-
- extern int isBackground;
- extern WindowPtr frontUserWindow();
-
- /*******************************************************
- * *
- * GetMenus is called at startup time to load the menu resources and store their *
- * handles for later use. *
- * *
- *******************************************************/
-
- getMenus()
- {
- Handle theMBar;
-
- theMBar = GetNewMBar( mBarID );
- SetMenuBar( theMBar );
- AddResMenu( GetMHandle( appleID ), 'DRVR' );
- DrawMenuBar();
- }
-
- /*******************************************************
- * *
- * DoCommand executes the selected menu command, and returns an integer *
- * telling whether a quit command was given. The parameter is the longword *
- * returned by either MenuSelect or MenuKey. *
- * *
- *******************************************************/
-
- int doCommand( p )
- long int p;
- {
- int result = 1, theMenu = HiWord(p), theCommand = LoWord(p);
-
- switch ( theMenu )
- {
- case appleID:
- doApple( theCommand );
- break;
- case fileID:
- result = doFile( theCommand );
- break;
- case editID:
- if ( !SystemEdit( theCommand ))
- doEdit( theCommand );
- break;
- case camID:
- doCam( theCommand );
- break;
- case toolID:
- doTool( theCommand );
- break;
- default: ;
- }
- HiliteMenu(0);
- return( result );
- }
-
- doApple( num )
- int num;
- {
- Str255 itemName;
- WindowPeek theWindow;
- int isDA;
-
- if ( num>2 )
- {
- theWindow = ( WindowPeek )FrontWindow();
- isDA = theWindow && theWindow->windowKind < 0;
- if( !isDA ) exportScrap();
- GetItem( GetMHandle( appleID ), num, itemName );
- installModalTrap();
- OpenDeskAcc( itemName );
- removeModalTrap();
- if( !isDA ) setBadScrap();
- }
- else doAbout();
- }
-
- doFile( num )
- int num;
- {
- int result = -1;
- WindowPtr theWindow;
-
- switch (num)
- {
- case fmNew:
- doNew( dataStatLine );
- break;
- case fmClose:
- theWindow = FrontWindow();
- if( theWindow ) doClose( theWindow );
- break;
- case fmQuit:
- doAllClose();
- killChannels();
- exportScrap();
- result = 0;
- break;
- default: ;
- }
- return( result );
- }
-
- doEdModify( theData, theCommand )
- dataPtr theData;
- int theCommand;
- {
- BitMap *changeBits;
- char *dest;
- long nextGen;
- int oldState, newState, needsDraw;
-
- oldState = stopData( theData, forceStop );
- newState = oldState;
- if( theData->isSelect ) {
- changeBits = &( theData->selBits );
- dest = theData->selBits.baseAddr;
- } else {
- changeBits = &( theData->offBits );
- dest = theData->bases[ 1 ];
- }
- switch( theCommand ) {
- case edErase:
- newState = dataStopped;
- eraseData( changeBits, dest );
- nextGen = 0;
- break;
- case edFill:
- newState = dataStopped;
- fillData( changeBits, dest );
- nextGen = 0;
- break;
- case edInvert:
- invertData( changeBits, dest );
- nextGen = theData->generation;
- break;
- case edRandomize:
- randomize( changeBits, dest );
- nextGen = 0;
- break;
- case edUndo:
- newState = dataStopped;
- nextGen = theData->undoGeneration;
- break;
- default: ;
- }
- if( !theData->isSelect ) {
- swapPlane( theData );
- theData->undoGeneration = theData->generation;
- theData->generation = nextGen;
- if( theData->cycleFlags ) startCycle( theData );
- restartData( theData, newState );
- needsDraw = bitsBadData + bitsBadGen;
- if( theCommand != edUndo ) theData->undoFlags |= undoData;
- } else {
- restartData( theData, oldState );
- needsDraw = bitsBadSel;
- }
- theData->changed = timer();
- return( needsDraw );
- }
-
- doEdit( theCommand )
- int theCommand;
- {
- WindowPeek theWindow = ( WindowPeek )frontUserWindow();
- dataHandle theDataHand;
- dataPtr theData;
- int toDraw = 0;
-
- if( theWindow && theWindow == ( WindowPeek )FrontWindow() ) {
- theDataHand = ( dataHandle )GetWRefCon( theWindow );
- HLock( theDataHand );
- theData = *theDataHand;
- if( theCommand == edUndo || theCommand > edClear )
- toDraw = doEdModify( theData, theCommand );
- else switch( theCommand ) {
- case edPaste:
- toDraw = doEdPaste( theData );
- break;
- case edCopy:
- case edCut:
- if( theData->isSelect )
- setMyClip( &( theData->selBits ), theData->selRgn );
- if( theCommand == edCopy ) break;
- case edClear:
- toDraw = doEdClear( theData );
- break;
- default: ;
- }
- HUnlock( theDataHand );
- if( toDraw & bitsBadAnts ) {
- activeAnts( theDataHand, -1 );
- toDraw -= bitsBadAnts;
- }
- if( toDraw ) {
- HLock( theDataHand );
- displayData( *theDataHand, toDraw, NULL );
- HUnlock( theDataHand );
- }
- }
- }
-
- startCycle( theData )
- dataPtr theData;
- {
- theData->cycleGeneration = theData->generation;
- theData->cycleFitLength = theData->cycleLength;
- if( theData->cycleFlags && theData->cycleBase )
- DisposHandle( theData->cycleBase );
- PtrToHand( theData->bases[ 0 ], &theData->cycleBase, theData->planeSize );
- if( theData->cycleBase ) HPurge( theData->cycleBase );
- }
-
- stopCycle( theData )
- dataPtr theData;
- {
- if( theData->cycleBase ) DisposHandle( theData->cycleBase );
- }
-
- doCam( theCommand )
- int theCommand;
- {
- WindowPtr theWindow;
- dataHandle theDataHand;
- dataPtr theData;
-
- theWindow = frontUserWindow();
- if( !theWindow ) return; /* should never happen */
- theDataHand = ( dataHandle )GetWRefCon( theWindow );
- HLock( theDataHand );
- theData = *theDataHand;
- switch( theCommand )
- {
- case camGo:
- if( theData->state == dataStopped ) ++isBackground;
- theData->state = dataRunning;
- break;
- case camStep:
- if( theData->state == dataStopped ) ++isBackground;
- theData->state = dataStepping;
- break;
- case camStop:
- stopData( theData, dontForceStop );
- break;
- case camRestart:
- if( !theData->cycleFlags ) startCycle( theData );
- theData->cycleFlags ^= cycleRestart;
- if( !theData->cycleFlags ) stopCycle( theData );
- break;
- case camDetect:
- if( !theData->cycleFlags ) startCycle( theData );
- theData->cycleFlags ^= cycleDetect;
- if( !theData->cycleFlags ) stopCycle( theData );
- break;
- default: ;
- }
- HUnlock( theDataHand );
- }
-
- doTool( theCommand )
- int theCommand;
- {
- setToolCurs( theCommand );
- }
-
- /*******************************************************
- * *
- * This gets called before doing a MenuSelect or a MenuKey to make sure that *
- * everything is checked or enabled properly. This is vitally important - in most *
- * places I check anyway, but sometimes I depend on the fact that some option *
- * can only be selected when it is appropriate. *
- * *
- *******************************************************/
-
- updateMenus()
- {
- WindowPtr theWindow;
-
- theWindow = FrontWindow();
- fixFileMenu( theWindow );
- fixEditMenu( theWindow );
- fixLifeMenu( theWindow );
- fixToolMenu( theWindow );
- }
-
- /*******************************************************
- * *
- * This is a hack - if I wanted to do it better, I could read the old value and then *
- * make a call for all those that had changed. Even better, each I would keep the *
- * old values internally, and never touch the menuInfo struct. However, this is *
- * much simpler. If it ever breaks, I'll just fix it or something. :-> *
- * *
- *******************************************************/
-
- changeEnable( menu, new )
- int menu;
- long new;
- {
- ( **GetMHandle( menu )).enableFlags = new;
- }
-
- fixFileMenu( theWindow )
- WindowPeek theWindow;
- {
- MenuHandle theMenu;
- static int wasClose = 0;
- int isClose;
-
- theMenu = GetMHandle( fileID );
- isClose = theWindow && theWindow->goAwayFlag;
- if( !isClose && wasClose ) DisableItem( theMenu, fmClose );
- else if( isClose && !wasClose ) EnableItem( theMenu, fmClose );
- wasClose = isClose;
- }
-
- fixEditMenu( theWindow )
- WindowPeek theWindow;
- {
- dataHandle theDataHand = NULL;
- long new = -1L ^ edGrayBits;
- int isWindow, isDA, isSelection, isUndo;
-
- isWindow = theWindow ? -1 : 0;
- isDA = isWindow && theWindow->windowKind < userKind;
- if( isWindow && !isDA ) theDataHand = ( dataHandle )GetWRefCon( theWindow );
- isSelection = isWindow && theWindow->windowKind == userKind &&
- ( **theDataHand ).isSelect;
- isUndo = isWindow && ( isDA || ( **theDataHand ).undoFlags != undoNone );
- if( !isUndo ) new ^= edUndoBit;
- if( !( couldPaste() || isDA ) || !isWindow ) new ^= edPasteBit;
- if( !( isSelection || isDA ) || !isWindow ) new ^= edSelectBits;
- if( isDA || !isWindow ) new ^= edModifyBits;
- changeEnable( editID, new );
- }
-
- fixLifeMenu( theWindow )
- WindowPeek theWindow;
- {
- MenuHandle theMenu;
- dataHandle theDataHand;
- dataPtr theData;
- long new = -1L ^ camGrayBits;
-
- if( theWindow && theWindow->windowKind >= userKind ) {
- theDataHand = ( dataHandle )GetWRefCon( theWindow );
- HLock( theDataHand );
- theData = *theDataHand;
- if( theData->state == dataRunning ) new ^= camGoBit;
- if( theData->state == dataStepping ) new ^= camStepBit;
- if( theData->state == dataStopped ) new ^= camStopBit;
- theMenu = GetMHandle( camID );
- CheckItem( theMenu, camRestart, theData->cycleFlags & cycleRestart );
- CheckItem( theMenu, camDetect, theData->cycleFlags & cycleDetect );
- HUnlock( theDataHand );
- } else new ^= camGoBit + camStepBit + camStopBit + camFlagBits;
- changeEnable( camID, new );
- }
-
- fixToolMenu()
- {
- MenuHandle theMenu;
- static int oldTool = 0;
- int newTool;
-
- newTool = getToolCurs();
- if( oldTool != newTool )
- {
- theMenu = GetMHandle( toolID );
- if( oldTool ) CheckItem( theMenu, oldTool, 0 );
- CheckItem( theMenu, newTool, -1 );
- oldTool = newTool;
- }
- }
-
-